package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.DetailForumActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.Models.Forum;
import com.lzw.bluetoothpractice.Models.Review;
import com.lzw.bluetoothpractice.Models._User;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.bean.CommentBean;
import com.lzw.bluetoothpractice.bean.ForumDetailBean;
import com.lzw.bluetoothpractice.bean.HealthyMessageListBean;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;


public class DetailForumAdapter extends RecyclerView.Adapter<DetailForumAdapter.ViewHolder> {
    private List<CommentBean.DataBean> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<CommentBean.DataBean> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }
    public DetailForumAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View view;
        ImageView head;  //头像
        TextView name;  //姓名
        TextView pointsum;  //点赞数
        Button point;  //点赞按钮
        TextView content;//回复的内容
        TextView time;  //回复时间

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view = itemView;
            head = (ImageView)view.findViewById(R.id.detail_reviews_head);
            name = (TextView)view.findViewById(R.id.detail_reviews_name);
            pointsum = (TextView)view.findViewById(R.id.detail_tv_point);
            point = (Button)view.findViewById(R.id.detail_bt_point);
            content = (TextView)view.findViewById(R.id.detail_reviews_content);
            time = (TextView)view.findViewById(R.id.detail_reviews_time);
        }
    }
    @Override //返回的是回复总数
    public int getItemCount() {
        return datas.size();
    }
    //核心代码，包括查询和对接
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CommentBean.DataBean review = datas.get(position);//得到的是单个回复
        Long user_id = review.getUserId();  //得到回复者id
        holder.content.setText(review.getCommentContent());
        holder.time.setText(review.getCreateTime().toLocaleString()+"");
       // holder.pointsum.setText(review.getPointsum());
        Glide.with(mcontext).load(AppConfig.BASE_URL+review.getPic()).into(holder.head);


        holder.name.setText(review.getUserName());



    }
    //得到各个内容
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView = LayoutInflater.from(mcontext).inflate(R.layout.detail_reviews,parent,false);
        return new ViewHolder(itemView);
    }
}
